﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Newtonsoft.Json;
using Power.Models;
using Power.View.Dialog;
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Power.ViewModel.Dialog
{
    public class TestRecordP1ViewModel : ViewModelBase
    {
        private TestRecordP1 model;
        public TestRecordP1ViewModel(ref DetectRecordSearchEntity entity,TestRecordP1 model)
        {
            this.model = model;
            Close = new RelayCommand(OnClose);
            CloseOK = new RelayCommand(OnCloseOK);
            if (entity.ID == -1)
            {
                Data = new DetectRecordSearchEntity()
                {
                    ID = 0,
                    StartWell = entity.StartWell,
                    EndWell = entity.EndWell,
                    Pip = entity.Pip,
                    Detect = entity.Detect,
                    Defect = entity.Defect, 
                    StartWellTypeList = Common.Common.GetSelectList(),
                    StartWellFuncTypeList = Common.Common.GetSelectList(),
                    StartWellMatList = Common.Common.GetSelectList(),
                    StartWellProblemList = Common.Common.GetSelectList(),
                    EndWellTypeList = Common.Common.GetSelectList(),
                    EndWellFuncTypeList = Common.Common.GetSelectList(),
                    EndWellMatList = Common.Common.GetSelectList(),
                    EndWellProblemList = Common.Common.GetSelectList(),
                    PipTypeList = Common.Common.GetSelectList(),
                    PipMatList = Common.Common.GetSelectList(),
                    DetectDirectionList = Common.Common.GetSelectList(),
                    DetectMethodList = Common.Common.GetSelectList(),
                    DefectTypeList = Common.Common.GetSelectList(),
                    DefectNameList = Common.Common.GetSelectList(),
                    DetectDateE = "2021-05-21",
                   DetectDateS = "2021-05-21"
                };
            }
            else {
                Data = entity;
            }
            entity = Data;
        }

        private void OnCloseOK()
        {
            Data.DetectDateE = this.model.DetectDateE.Text;
            Data.DetectDateS = this.model.DetectDateS.Text;
            this.model.DialogResult = true;
            this.model.Close();
        }

        private void OnClose()
        {
            this.model.DialogResult = false;
            this.model.Close();
        }

        #region 
        public RelayCommand Close { get; private set; }

        public RelayCommand CloseOK { get; private set; }
        #endregion

        #region 数据绑定
        private DetectRecordSearchEntity data;
        public DetectRecordSearchEntity Data
        {
            get
            {
                return data;
            }
            set
            {
                data = value;
                RaisePropertyChanged();
            }
        }
        #endregion
    }
}
